package com.jzg.jcptadmin.adpter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.data.vo.ChooseResultData;

import java.util.List;

/**
 * author: guochen
 * date: 2016/11/8 16:09
 * email: 
 */
public class ChooseResultAdapter1 extends BaseAdapter{
    private Context context;
    private List<ChooseResultData.DataBean> datas;
    final int TYPE_1 = 0;
    final int TYPE_2 = 1;
    private ViewHolderTitle viewHolderTitle;
    private ViewHolder viewHolder;
    public ChooseResultAdapter1(Context context, List<ChooseResultData.DataBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }


    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int itemViewType = getItemViewType(position);
        if(convertView==null){
            switch (itemViewType){
                case TYPE_1:
                    viewHolderTitle = new ViewHolderTitle();
                    convertView = View.inflate(context, R.layout.choose_result_title,null);
                    viewHolderTitle.title = (TextView) convertView.findViewById(R.id.tv_title);
                    convertView.setTag(viewHolderTitle);
                    break;
                case TYPE_2:
                    viewHolder = new ViewHolder();
                    convertView = View.inflate(context, R.layout.choose_result_item,null);
                    viewHolder.result = (TextView) convertView.findViewById(R.id.tv_result);
                    viewHolder.checkBox = (CheckBox) convertView.findViewById(R.id.checkbox);
                    viewHolder.ll_linear = (RelativeLayout) convertView.findViewById(R.id.ll_linear);
                    convertView.setTag(viewHolder);
                    break;
                default:

                    break;
            }
        }else {
            switch (itemViewType) {
                case TYPE_1:
                    viewHolderTitle = (ViewHolderTitle) convertView.getTag();
                    break;
                case TYPE_2:
                    viewHolder = (ViewHolder) convertView.getTag();
                    break;
                default:

                    break;
            }
        }
//设置数据
        switch (itemViewType) {
//            case TYPE_1:
//                viewHolderTitle = (ViewHolderTitle) convertView.getTag();
//                viewHolderTitle.title.setText(datas.get(position).getGroupName());
//                break;
//            case TYPE_2:
//                viewHolder = (ViewHolder) convertView.getTag();
//                viewHolder.result.setText(datas.get(position).getItemValue());
//                viewHolder.checkBox.setSelected(datas.get(position).isSelect());
//                if(datas.get(position).isSelect()){
//                    viewHolder.ll_linear.setBackgroundResource(R.drawable.btn_result_sel);
//                }else{
//                    viewHolder.ll_linear.setBackgroundResource(R.drawable.btn_result_nor);
//                }
//                break;
//            default:

//                break;
        }
        return convertView;
    }
    public class ViewHolder {

        public TextView result;
        public CheckBox checkBox;
        public RelativeLayout ll_linear;

    }

    class ViewHolderTitle {
        public TextView title;

    }
}
